#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int N = 1010, mod = 998244353;
string s[N];
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int a, b, c, d, e;
		scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
		//cin>>a>>b>>c>>d>>e;
	}
	int ans = 0;
	for (int i = 0; i < m; i++)
	{
		int f = 1;
		for (int j = 0; j < n; j++)
		{
			if (s[j][i] == '0')
			{
				f = 0;
				break;
			}
		}
		if (f) ans++;
	}
	cout << ans;

	return 0;
}

